﻿using Freebase4net.Interfaces;
using Freebase4net.Operators.Bases;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Freebase4net.Operators
{
    public class ButNotOperator : OperatorBase, IOperator
    {
        private string _value;

        public ButNotOperator(params string[] values)
            : base(values)
        {
            _value = string.Join("###", values);


        }

        public string CreateJson(string key)
        {
            try
            {
                StringBuilder builder = new StringBuilder();

                string[] values = _value.Split(new string[] { "###" }, StringSplitOptions.RemoveEmptyEntries);
                builder.AppendFormat("\"{0}!=\":\"{1}\",", key, values[0]);
                if (values.Length > 1)
                {
                    builder.AppendLine();
                }
                int i = 1;
                for (char c = 'A'; c <= 'Z' && i < values.Length; c++, i++)
                {
                    builder.AppendFormat("\"{2}:{0}!=\":\"{1}\",", key, values[i], c.ToString().ToLower());
                    if (i != values.Length - 1)
                    {
                        builder.AppendLine();
                    }
                }
                builder = builder.Remove(builder.Length - 1, 1);


                return builder.ToString();
            }
            catch (Exception e)
            {
                throw new OperatorArgumentException("string");
            }
        }
    }
}
